var request=require('request');
class ManagerUser{
	constructor(data_center_url){
		this.data_center_url=data_center_url
    }
	login(user_name,password){
		return new Promise((resolve, reject) => {
			let data={
				"user_name":user_name,
				"true_name":true_name
			}
			request({
				url:this.data_center_url+'update_mes_user',
				method:'POST',
				json: true,
				headers:{'Content-Type':'text/json' },
				body:data
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});
		})		
	}
	updateMesUser(user_name,true_name){
		return new Promise((resolve, reject) => {
			let data={
				"user_name":user_name,
				"true_name":true_name
			}
			request({
				url:this.data_center_url+'update_mes_user',
				method:'POST',
				json: true,
				headers:{'Content-Type':'text/json' },
				body:data
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});
		})		
	}
	getApsUsers(page,page_size){
		return new Promise((resolve, reject) => {
			let data={
				"page":page,
				"page_size":page_size
			}
			request({
				url:this.data_center_url+'get_aps_users',
				method:'POST',
				json: true,
				headers:{'Content-Type':'text/json' },
				body:data
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});
		})
	}
	addApsToDataCenter(user){
		return new Promise((resolve, reject) => {
			request({
				url:this.data_center_url+'add_aps_user',
				method:'POST',
				json: true,
				headers:{'Content-Type':'text/json' },
				body:user
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});	
		})		
	}
	addApsUserToAps(user){
		return new Promise((resolve, reject) => {
			request({
				url:"http://192.168.1.168:8080/aps/user/register/"+user.user_name+"/"+user.md5,
				method:'POST',
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});
		})		
	}
	setApsStatus(user,status){
		return new Promise((resolve, reject) => {
			request({
				url:"http://192.168.1.168:8080/aps/user/setUserPermission/"+user.user_name+"/"+status,
				method:'POST',
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});
		})			
	}
	searchApsUser(value){
		return new Promise((resolve, reject) => {
			let data={
				"user_name":value,
			}
			request({
				url:this.data_center_url+'search_aps_user',
				method:'POST',
				json: true,
				headers:{'Content-Type':'text/json' },
				body:data
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});
		})			
	}
	getMesUsers(page,page_size){
		return new Promise((resolve, reject) => {
			let data={
				"page":page,
				"page_size":page_size
			}
			request({
				url:this.data_center_url+'get_mes_users',
				method:'POST',
				json: true,
				headers:{'Content-Type':'text/json' },
				body:data
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});
		})		
	}
	addMesUserToDataCenter(user){
		return new Promise((resolve, reject) => {
			request({
				url:this.data_center_url+'add_mes_user',
				method:'POST',
				json: true,
				headers:{'Content-Type':'text/json' },
				body:user
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});	
		})		
	}
	addMesUserToMes(user){
		return new Promise((resolve, reject) => {
			request({
				url:"http://192.168.1.166:90/api/DataCenterSync.ashx?action=Account&OperateType=0&data={\"AccountId\":\""+user.user_name+"\",\"OpenCode\":\""+user.user_name+"\",employeeId:\""+user.user_name+"\",\"password\":\"1234qwer\",\"NickName\":\""+user.user_name+"\",\"Sex\":1,\"CreateUser\":\"data-center\",\"CreateTime\":\"2021-04-27 00:00:00.000\",\"UpdateUser\":\"data-center\",\"UpdateTime\":\"2021-04-27 00:00:00.000\",\"IsDelete\":0}",
				method:'GET',
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});
		})			
	}
	specialMesFun(){
		return new Promise((resolve, reject) => {

			request({
				url:"http://192.168.1.161:8080/datacenter/job/executeScriptById?id=20",
				method:'POST',
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});
		})			
	}
	setMesUser(){
		
	}
	searchMesUser(value){
		return new Promise((resolve, reject) => {
			let data={
				"user_name":value,
			}
			request({
				url:this.data_center_url+'search_mes_user',
				method:'POST',
				json: true,
				headers:{'Content-Type':'text/json' },
				body:data
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});
		})		
	}
    getUsers(page,page_size){
		return new Promise((resolve, reject) => {
			let data={
				"page":page,
				"page_size":page_size
			}
			request({
				url:this.data_center_url+'get_users',
				method:'POST',
				json: true,
				headers:{'Content-Type':'text/json' },
				body:data
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});	
		})
    }
	getCrmUsers(page,page_size){
		return new Promise((resolve, reject) => {
			let data={
				"page":page,
				"page_size":page_size
			}
			request({
				url:this.data_center_url+'get_crm_users',
				method:'POST',
				json: true,
				headers:{'Content-Type':'text/json' },
				body:data
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});
		})		
	}
	addCrmUserToDataCenter(user){
		return new Promise((resolve, reject) => {
			request({
				url:this.data_center_url+'add_crm_user',
				method:'POST',
				json: true,
				headers:{'Content-Type':'text/json' },
				body:user
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});	
		})		
	}
	addCrmUserToCrm(user){
		return new Promise((resolve, reject) => {
			request({
				url:"http://192.168.1.164:8030/api/register/"+user.user_name+"/"+user.md5,
				method:'POST',
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});
		})			
	}
	setCrmUser(){
		
	}
	searchCrmUser(value){
		return new Promise((resolve, reject) => {
			let data={
				"user_name":value,
			}
			request({
				url:this.data_center_url+'search_crm_user',
				method:'POST',
				json: true,
				headers:{'Content-Type':'text/json' },
				body:data
			},(error,response,body)=>{
				if(!error && response.statusCode==200){
					resolve(body)
				}else{
					resolve(error)
				}
			});
		})		
	}
}

module.exports = ManagerUser;